/**
 * 宏观事件类 - 代表可能影响市场的宏观经济事件
 */
class MacroEvent {
  /**
   * 创建宏观事件
   * @param {Object} config - 事件配置
   */
  constructor(config = {}) {
    this.type = config.type || 'generic'; // 事件类型: economic, political, natural, etc.
    this.impact = config.impact || 0; // 影响程度 [-1, 1]
    this.duration = config.duration || 1; // 持续时间
    this.probability = config.probability || 0.01; // 发生概率
    this.name = config.name || `${this.type} event`;
    this.active = false;
    this.remainingDuration = 0;
    this.targetAssets = config.targetAssets || 'all'; // 目标资产: 'all', 'asset1', 'asset2', ['asset1', 'asset2']
  }

  /**
   * 激活事件
   */
  activate() {
    this.active = true;
    this.remainingDuration = this.duration;
  }

  /**
   * 更新事件状态
   * @returns {boolean} 事件是否仍然活跃
   */
  update() {
    if (this.active) {
      this.remainingDuration--;
      if (this.remainingDuration <= 0) {
        this.active = false;
      }
    }
    return this.active;
  }

  /**
   * 获取事件对资产的影响
   * @param {string} assetId - 资产ID
   * @returns {number} 价格影响系数
   */
  getAssetImpact(assetId) {
    // 根据目标资产设置决定是否对资产产生影响
    if (this.targetAssets === 'all') {
      return this.impact;
    } else if (Array.isArray(this.targetAssets)) {
      return this.targetAssets.includes(assetId) ? this.impact : 0;
    } else {
      return this.targetAssets === assetId ? this.impact : 0;
    }
  }
}

module.exports = MacroEvent;